import java.util.LinkedList;
import java.util.Scanner;

public class HomeWork16_01{
    public static void main(String[] args){        
        GuessNumb gn = new GuessNumb(10);
        gn.execute();        
    }
}

class GuessNumb{
    private Scanner scan;
    private int time;
    private LinkedList<Integer> list;
    private LinkedList<int[]> guessList;
    
    public GuessNumb(int time){
        this.scan = new Scanner(System.in);        
        
        //最多猜测次数
        this.time = time;
        
        //list作为随机生成的4个数的线性表
        this.list = new LinkedList<Integer>();
        for(int i = 0; i < 4; i++){
            int tmp = (int)(Math.random()*10);
            list.add(tmp);
        }
        
        //guessList用于存储之前猜测的所有组合
        this.guessList = new LinkedList<int[]>();
    }
    
    public void execute(){
        int t = time;
        while(t-- >0){
            //显示玩家猜测的历史纪录
            System.out.println("\n***************\n");
            System.out.println("之前的输入：");
            preGuess();
            System.out.println();
            
            //获取新的猜测，并获取猜对的结果数目count
            System.out.print("请输入您的猜测: ");
            int count = newGuess();
            
            if(count < 4){
                System.out.println("\n有" + count + "个数字猜测正确");
            }else{
                System.out.println("\n猜对啦！!!!!!!!");
                break;
            }
        }
        
        if(t == 0){
            System.out.println("失败了..");
        }
    }
    
    //之前用户的猜测历史纪录
    private void preGuess(){
        for(int i = 0; i < guessList.size(); i++){
            for(int j = 0; j < 4; j++){
                System.out.print(guessList.get(i)[j] + " ");
            }
            System.out.println();
        }
    }
    
    //获取新的猜测，并返回猜对的结果数
    private int newGuess(){
        int[] arrTmp = new int[4];        
        int count = 0;
        for(int i = 0; i < arrTmp.length; i++){
            arrTmp[i] = scan.nextInt();
            if(arrTmp[i] == list.get(i)){
                ++count;
            }
        }
        guessList.add(arrTmp);
        
        return count;
    }
}